package com.mytest.lesson100.serviceimpl;

import com.github.pagehelper.Page;
import com.mytest.lesson100.dao.ExpertVOMapper;
import com.mytest.lesson100.model.ExpertVO;
import com.mytest.lesson100.model.ExpertVOExample;
import com.mytest.lesson100.service.ExpertService;

import javax.annotation.Resource;
import java.util.List;

public class ExpertServiceImpl implements ExpertService {
    @Resource
    private ExpertVOMapper expertVOMapper;

    @Override
    public List<ExpertVO> list(int pageNo,int pageSize,Boolean recommend) {
        ExpertVOExample example = new ExpertVOExample();
        if(recommend!=null){
            example.createCriteria().andRecommendEqualTo(recommend);
        }
        example.setOrderByClause("id desc");
//        example.setPage(new Page(pageNo, pageSize));
        return expertVOMapper.selectByExample(example);
    }

    @Override
    public ExpertVO getById(int id) {
        return expertVOMapper.selectByPrimaryKey(id);
    }

    @Override
    public void addAdvisoryCount(int id) {
        ExpertVO expert = expertVOMapper.selectByPrimaryKey(id);
        expert.setAdvisoryCount(expert.getAdvisoryCount()==null?1:(expert.getAdvisoryCount()+1));
        expertVOMapper.updateByPrimaryKey(expert);
    }


}
